<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/templateListar.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="conteudo">
		<ui:param name="actionBean" value="#{animalMB}" />

		<h:form id="frm">
			<p:hotkey bind="esc"
				handler="document.getElementById('frmTab:btnCancelar').click()" />
		</h:form>

		<h:form id="frmTab">
			<p:commandButton id="btnCancelar" action="#{animalMB.sair}"
				style="display:none" immediate="true" value="sair">
			</p:commandButton>

			<p:dataTable id="tabela" var="item" value="#{animalMB.lista}"
				paginator="true" rows="10" emptyMessage="Não há registros na lista"
				paginatorPosition="bottom"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				currentPageReportTemplate="(Página: {currentPage}/{totalPages})"
				rowsPerPageTemplate="10,15,25,50,100" rowKey="#{item.codigo}"
				selectionMode="single">
				<f:facet name="header">Cadastro de Animais</f:facet>
				<p:column headerText="Codigo" sortBy="#{item.codigo}">
					<h:outputText value="#{item.codigo}" />
				</p:column>
				<p:column headerText="Data de Cadastro"
					sortBy="#{item.dataCadastro}">
					<h:outputText value="#{item.dataCadastro}">
						<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-3" />
					</h:outputText>
				</p:column>

				<p:column headerText="Cliente"
					sortBy="#{item.cliente.dadosCadastro.nome}"
					filterMatchMode="contains"
					filterBy="#{item.cliente.dadosCadastro.nome}">
					<h:outputText value="#{item.cliente.dadosCadastro.nome}" />
				</p:column>

				<p:column headerText="Nome" sortBy="#{item.nomeAnimal}"
					filterMatchMode="contains" filterBy="#{item.nomeAnimal}">
					<h:outputText value="#{item.nomeAnimal}" />
				</p:column>
				<p:column headerText="Tipo" sortBy="#{item.tipoAnimal.descricao}"
					filterMatchMode="contains" filterBy="#{item.tipoAnimal.descricao}">
					<h:outputText value="#{item.tipoAnimal.descricao}" />
				</p:column>
				<p:column headerText="Data de Nascimento"
					sortBy="#{item.dataNascimento}">
					<h:outputText value="#{item.dataNascimento}">
						<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-3" />
					</h:outputText>
				</p:column>


				<p:column headerText="Ação" style="text-align:center">

					<p:commandButton actionListener="#{animalMB.abrirModal}"
						styleClass="styleBotao" ajax="true" title="Alterar"
						icon="ui-icon-pencil" oncomplete="dialogCadastroAnimal.show()"
						update=":dialogCadastro,:frmDialogAnimal">
						<f:param name="modooperacao" value="ALTERAR" />
						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{animalMB.animalSelecionado}" />
					</p:commandButton>

					<p:commandButton actionListener="#{animalMB.abrirModal}"
						styleClass="styleBotao" title="Consultar" icon="ui-icon-search"
						ajax="true" oncomplete="dialogCadastroAnimal.show()"
						update=":dialogCadastro">
						<f:param name="modooperacao" value="CONSULTAR" />
						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{animalMB.animalSelecionado}" />
					</p:commandButton>

					<p:commandButton actionListener="#{animalMB.excluir}"
						styleClass="styleRed" icon="ui-icon-close" title="Excluir"
						update=":Excluir" oncomplete="confirmation.show()">

						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{animalMB.animalSelecionado}" />
					</p:commandButton>

				</p:column>


			</p:dataTable>
		</h:form>
		<ui:include src="dialogCadastroAnimal.xhtml" />
		<ui:include src="/includes/confirmacaoExcluir.xhtml" />
	</ui:define>
</ui:composition>
